<!DOCTYPE html>
<html>
  <head>
  	<div th:include="base-libs :: base-libs" />
  	<link th:href="@{/service/css/xymb.css}" rel="stylesheet"/>
  	<script th:src="@{/service/js/xymb.js}"></script>
    <title>新建医联体-编辑协议</title>
	
    <meta name="keywords" content="keyword1,keyword2,keyword3">
    <meta name="description" content="this is my page">
    <meta name="content-type" content="text/html; charset=UTF-8">
    
    <style>
    	#btnBox{
    		text-align:center;
    		height:40px;
    		line-height:40px;
    		border:0;
    		overflow:hidden;
    		background:#f9f9f9;
    	}
    	.panel,.panel-header,.panel-body{
    		width:100% !important;
    	}
    </style>
    
    <script>
    	var yltJbxx = StoreCache.removeCache("yltJbxx");//医联体基本信息（包含机构id）
    	var yltJgxx = StoreCache.removeCache("yltJgxx");//机构信息
    	$(function(){
    		initView();
    	})
    	
    	function initView(){
    		if($.isEmptyObject(yltJbxx)) {
    			$.QuickAlert.alertFail({content: '数据丢失，请重新进入！'});
    			return;
    		}
    		
    		//初始化删除服务项的方法
    		initDeleteFwxMethod();
    		
    		$.QuickRemote.AjaxJson( contextRoot + "xymb/queryXymb", function(result){
                var content = result["CONTENT"];
                $("#center").append(content);
                $("textarea").attr("readonly","readonly");
                //隐藏甲乙方信息table
                hideOrShowJyfxx('none');
            }, {XYMBID: yltJbxx.XYID});
    	}
    	
    	/** 保存协议 */
    	function btnSaveHandler(){
    		var length = $("#tabFwx tbody tr").length;
    		if(length > 0){
    	        $(".dynamicText").each(function(){
    	            $(this).text($(this).val());
    	        });
    	        var content = $(".xymbContent").prop("outerHTML");
    	        var FWIDS = getFwids();
    	        /*协议页面*/
    	        var XYMB = {
    	        		CONTENT: content,
    	        		FWIDS: FWIDS,
    	        }
    	        
    	        $.QuickRemote.AjaxJson(contextRoot + "xymb/saveXyAndResutXyid", saveHandler, XYMB);
    	    }else{
    	    	$.QuickAlert.alertFail({content: '协议服务内容不能为空！'});
    	    }
    	}

    	/** 保存协议回调 */
    	function saveHandler(result){
    	    if (result["state"]) {
    	    	yltJbxx.XYID = result.XYMBID;
    	    	//alert(JSON.stringify(yltJbxx));
    	    	//保存医联体
    	    	$.QuickRemote.AjaxJson(contextRoot + "qysq/save", function(result){
    	        	var info = result["info"];
    				if (result["state"]) {
    					$.QuickAlert.alertNormal('医联体新建成功！',{callback: function(){
    						$.QuickUrlUtils.redirectUrl("index.html");
    					}});
    				} else {
    					$.QuickAlert.alertFail({
    						content : info["faultInfo"]
    					});
    				}
    	        }, yltJbxx);
    	    } else {
    	        $.QuickAlert.alertFail({
    	            content : result.info["faultInfo"]
    	        });
    	    }
    	}
    	
    	
    	/**返回按钮*/
		function btnBackHandler(){
			StoreCache.setCache('yltJbxx',yltJbxx);
			StoreCache.setCache('yltJgxx',yltJgxx);
		    $.QuickUrlUtils.back();
		}
    </script>

  </head>
  
  <body class="easyui-layout">
    	<div region="center" id="center"></div>
    	<div region="south" id="btnBox">
    		<button onclick="btnSaveHandler()" type="button">提交</button>
    		<button onclick="btnBackHandler()" type="button">返回</button>
    	</div>
  </body>
  <script type="text/html" id="trFwx">
    <tr>
        <td>
            <span name="XH">1</span>
            <span name="FWID" style="display: none;"></span>
        </td>
        <td>
            <span name="FWMC"></span>
        </td>
        <td>
            <span name="FWNR"></span>
        </td>
        <td>
            <a class="trFwxBtn">移除</a>
        </td>
    </tr>
</script>
</html>
